<HTML><HEAD><TITLE>library(tentative_constraints)</TITLE></HEAD><BODY>
[ <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]<H1>library(tentative_constraints)</H1>
Tentative value implementations for some basic constraints
<H2>Predicates</H2>
<BLOCKQUOTE>
<DL>
<DT><A HREF="alldifferent_t-2.html"><STRONG>alldifferent_t(+Cs, +MC)</STRONG></A></DT>
<DD>Tentative value implementation of alldifferent constraint</DD>
<DT><A HREF="alldifferent_t-3.html"><STRONG>alldifferent_t(+Xs, +Cs, +MC)</STRONG></A></DT>
<DD>Tentative value implementation of alldifferent/2 constraint</DD>
<DT><A HREF="eq_t-3.html"><STRONG>eq_t(?X, ?Y, +MC)</STRONG></A></DT>
<DD>Tentative value implementation of $=/2 arithmetic equality constraint</DD>
<DT><A HREF="integral_t-3.html"><STRONG>integral_t(?X, ?Epsilon, +MC)</STRONG></A></DT>
<DD>Tentative value implementation of approximate integrality</DD>
<DT><A HREF="neq_t-3.html"><STRONG>neq_t(?X, ?Y, +MC)</STRONG></A></DT>
<DD>Tentative value implementation of $\=/2 arithmetic disequality constraint</DD>
</DL>
</BLOCKQUOTE>
<H2>Reexports</H2>
<BLOCKQUOTE><DL>
<DT><STRONG>reexport <A HREF="../../lib/tentative/index.html">tentative</A></STRONG></DT><DD></DD>
</DL></BLOCKQUOTE>
<H2>Other Exports</H2>
<BLOCKQUOTE><DL>
<DT><STRONG>export op(700, xfx, $=)</STRONG></DT><DD></DD>
<DT><STRONG>export op(700, xfx, $\=)</STRONG></DT><DD></DD>
</DL></BLOCKQUOTE>
<H2>Description</H2>

    This library contains tentative value implementations for some basic
    constraints.  It is intended to be used together with lib(tentative),
    which provides the underlying primitives and facilities to create
    tentative variables, manage constraint sets, and to do search.

<H2>Examples</H2>
<PRE>
    %
    % The following code implements a solution to the N-queens problem,
    % using a steepest-ascent hill-climbing heuristic.
    %

    :- lib(tentative).
    :- lib(tentative_constraints).

    queens(N, Board) :-
	    dim(Board, [N]),			% make variables
	    tent_set_random(Board, 1..N),	% init tentative values

	    dim(Pos, [N]),			% aux arrays of constants
	    ( foreacharg(I,Pos), for(I,0,N-1) do true ),
	    dim(Neg, [N]),
	    ( foreacharg(I,Neg), for(I,0,-N+1,-1) do true ),

	    CS :~ alldifferent(Board),		% setup constraints ...
	    CS :~ alldifferent(Board, Pos),	% ... in conflict set CS
	    CS :~ alldifferent(Board, Neg),

	    cs_violations(CS, TotalViolation),	% search part
	    steepest(Board, N, TotalViolation),

	    tent_fix(Board),			% instantiate variables
	    cs_clear_satisfied(CS).		% clean up conflict set


    steepest(Board, N, Violations) :-
	    vs_create(Board, Vars),		% create variable set
	    Violations tent_get V0,		% initial violations
	    SampleSize is fix(sqrt(N)),		% neighbourhood size
	    (
		fromto(V0,_V1,V2,0),		% until no violations left
		param(Vars,N,SampleSize,Violations)
	    do
		vs_random_worst(Vars, X),	% get a most violated variable
		tent_minimize_random(		% find a best neighbour
		    (				% nondeterministic move
			random_sample(1..N,SampleSize,I),
			X tent_set I
		    ),
		    Violations,			% violation variable
		    I				% best move-id
		),
		X tent_set I,			% do the move
		Violations tent_get V2		% new violations
	    ).
</PRE>
<H2>About</H2><UL COMPACT>
<LI><STRONG>Author: </STRONG>Joachim Schimpf
<LI><STRONG>Copyright &copy; </STRONG>Cisco Systems
<LI><STRONG>Date: </STRONG>$Date: 2009/02/19 05:45:20 $
</UL>
<H2>See Also</H2>
<A HREF="../../lib/tentative/index.html">library(tentative)</A><HR>Generated from tentative_constraints.eci on 2009-05-27 01:25
</BODY></HTML>
